<template>
  <div class="access-records ">
    <div class="records-container left-back">
      <div class="records-list" :class="{ 'loading': isLoading }">
        <div v-if="isLoading" class="loading-overlay">
          <div class="loading-spinner"></div>
        </div>
        <div class="record-item" v-for="(record, index) in records" :key="index">
          <div class="record-content">
            <div class="person-info">
              <span class="name">{{ record.name }}</span>
              <span class="team">{{ record.teamName }}</span>
            </div>
            <div class="access-time">
              <span :class="['access-type', record.type === '出场' ? 'exit' : 'entry']">
                {{ record.type }}
              </span>
              {{ record.time }}
            </div>
          </div>
        </div>
      </div>
    </div>
    <img src="@/assets/layer/mock3.png" style="width: 100%;margin-top: 55px;
    height: 320px;">
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
import { getAccessRecords } from "@/js/api/businessApi.js"
const records = ref([])
const isLoading = ref(false)
let refreshInterval = null

// 模拟数据，实际使用时替换为API调用
const getAccessRecordsData = () => {
  getAccessRecords({projectId: "19"}).then((data)=>{
    records.value = (data && data.data) || [
    {
        "time": "2025-04-05 10:00:00",
        "name": "张三",
        "sn": "1234567890",
        "teamName": "xxxx班组",
        "type": "出场"
        },    {
        "time": "2025-04-05 10:00:00",
        "name": "张三",
        "sn": "1234567890",
        "teamName": "xxxx班组",
        "type": "出场"
        },    {
        "time": "2025-04-05 10:00:00",
        "name": "张三",
        "sn": "1234567890",
        "teamName": "xxxx班组",
        "type": "出场"
        },    {
        "time": "2025-04-05 10:00:00",
        "name": "张三",
        "sn": "1234567890",
        "teamName": "xxxx班组",
        "type": "出场"
        },    {
        "time": "2025-04-05 10:00:00",
        "name": "张三",
        "sn": "1234567890",
        "teamName": "xxxx班组",
        "type": "出场"
        },
        {
        "time": "2025-04-05 10:00:00",
        "name": "张三",
        "sn": "1234567890",
        "teamName": "xxxx班组",
        "type": "出场"
        },
        {
        "time": "2025-04-05 10:00:00",
        "name": "张三",
        "sn": "1234567890",
        "teamName": "xxxx班组",
        "type": "出场"
        },
        {
        "time": "2025-04-05 10:00:00",
        "name": "张三",
        "sn": "1234567890",
        "teamName": "xxxx班组",
        "type": "出场"
        },
        {
        "time": "2025-04-05 10:00:00",
        "name": "张三",
        "sn": "1234567890",
        "teamName": "xxxx班组",
        "type": "出场"
        },
        {
        "time": "2025-04-05 10:00:00",
        "name": "张三",
        "sn": "1234567890",
        "teamName": "xxxx班组",
        "type": "出场"
        }
    ]
  })
}

onMounted(() => {
    getAccessRecordsData()
})

</script>

<style scoped>
.access-records {
  border-radius: 8px;
  padding: 20px;
  color: white;
  height: 100%;
  overflow-y: auto;
  position: relative;
  /* height: 353px; */
}

.records-container {
  height: 100%;
  overflow-y: auto;
  position: relative;
  height: 434px;
}

.records-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  transition: opacity 0.3s;
}

.records-list.loading {
  opacity: 0.6;
}

.loading-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
}

.loading-spinner {
  width: 30px;
  height: 30px;
  border: 3px solid rgba(79, 204, 255, 0.3);
  border-radius: 50%;
  border-top-color: #4FCCFF;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.record-item {
 font-size: 19px;
  height: 42px;
  background: url("@/assets/layer/access-records.png") no-repeat center center;
}

.record-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
}

.person-info {
  display: flex;
  gap: 16px;
  align-items: center;
}

.name {
  font-size: 16px;
  color: #fff;
}

.team {
  font-size: 14px;
  color: #4FCCFF;
}

.access-time {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #8F959E;
  font-size: 14px;
}

.access-type {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
}

.exit {
  background-color: rgba(255, 87, 87, 0.1);
  color: #FF5757;
}

.entry {
  background-color: rgba(79, 204, 255, 0.1);
  color: #4FCCFF;
}

.divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
  margin: 12px 16px 0;
}

@media (max-width: 768px) {
  .access-records {
    padding: 12px;
  }

  .record-content {
    padding: 0 12px;
  }

  .person-info {
    gap: 12px;
  }

  .name {
    font-size: 14px;
  }

  .team {
    font-size: 12px;
  }

  .access-time {
    font-size: 12px;
    gap: 8px;
  }
}
</style> 